// 放不同 action 的地方
import * as actionTypes from './constants';
import { fromJS } from 'immutable';
import { getBannerRequest, getRecommendListRequest } from '../../../api/request';


export const changeBannerList = (data) => ({
        type: actionTypes.CHANGE_BANNER,
        data: fromJS(data),
});

export const changeRecommendList = (data) => ({
    type: actionTypes.CHANGE_RECOMMEND_LIST,
    data: fromJS(data),
});

export const changeEnterLoading = (data) => ({
    type: actionTypes.CHANGE_ENTER_LOADIND,
    data,
});

export const getBannerList = () => {
    return (dispatch) => {
        getBannerRequest().then(data => {
            dispatch(changeBannerList(data.banners));
        }).catch(() => {
            console.error('轮播图传输错误！')
        })
    }
};

export const getRecommendList = () => {
    return (dispatch) => {
        getRecommendListRequest().then(data => {
            dispatch(changeRecommendList(data.result));
            // 改变loading
            dispatch(changeEnterLoading(false));
        }).catch(() => {
            console.error('推荐歌单传输错误！')
        })
    }
};